/*     */ package com.chw.filter;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import javax.servlet.Filter;
/*     */ import javax.servlet.FilterChain;
/*     */ import javax.servlet.FilterConfig;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.ServletRequest;
/*     */ import javax.servlet.ServletResponse;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpServletResponseWrapper;
/*     */ import javax.servlet.http.HttpSession;
/*     */ 
/*     */ public class LoginAdminFilter
/*     */   implements Filter
/*     */ {
/*     */   public FilterConfig config;
/*     */ 
/*     */   public static boolean isContains(String container, String regx)
/*     */   {
/*  31 */     boolean result = false;
/*     */ 
/*  33 */     if (container.toUpperCase().contains(regx.toUpperCase())) {
/*  34 */       return true;
/*     */     }
/*  36 */     return result;
/*     */   }
/*     */ 
/*     */   public static boolean isContainsIndex(String container, String regx)
/*     */   {
/*  41 */     boolean result = false;
/*     */ 
/*  43 */     String[] regxs = regx.split(",");
/*     */ 
/*  45 */     if ((container.toUpperCase().contains(regxs[2].toUpperCase())) && 
/*  46 */       (container.toUpperCase().length() <= 13)) {
/*  47 */       return true;
/*     */     }
/*     */ 
/*  52 */     return result;
/*     */   }
/*     */ 
/*     */   public void setFilterConfig(FilterConfig config)
/*     */   {
/*  58 */     this.config = config;
/*     */   }
/*     */ 
/*     */   public FilterConfig getFilterConfig() {
/*  62 */     return this.config;
/*     */   }
/*     */ 
/*     */   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
/*     */     throws IOException, ServletException
/*     */   {
/*  76 */     HttpServletRequest httpreq = (HttpServletRequest)request;
/*     */ 
/*  79 */     HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse)response);
/*     */ 
/*  81 */     String logonStrings = this.config.getInitParameter("logonStrings");
/*  82 */     String redirectPath = httpreq.getContextPath() + this.config.getInitParameter("redirectPath");
/*     */ 
/*  84 */     String logonStr = logonStrings;
/*  85 */     Object user = httpreq.getSession().getAttribute("userName");
/*  86 */     Object token = httpreq.getSession().getAttribute("token");
/*     */ 
/*  88 */     String includeStrings = this.config.getInitParameter("includeStrings");
/*  89 */     String includeStr = includeStrings;
/*  90 */     if ((user == null) && (token == null)) {
/*  91 */       if (isContains(httpreq.getRequestURI(), includeStr)) {
/*  92 */         chain.doFilter(request, response);
/*  93 */         return;
/*  94 */       }if ((isContains(httpreq.getRequestURI(), logonStr)) || (isContains(httpreq.getRequestURI(), redirectPath))) {
/*  95 */         chain.doFilter(request, response);
/*  96 */         return;
/*     */       }
/*  98 */       wrapper.sendRedirect(redirectPath);
/*     */     }
/*     */     else {
/* 101 */       if (isContains(httpreq.getRequestURI(), logonStr)) {
/* 102 */         wrapper.sendRedirect(redirectPath);
/* 103 */         return;
/*     */       }
/* 105 */       chain.doFilter(request, response);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void destroy() {
/* 110 */     this.config = null;
/*     */   }
/*     */ 
/*     */   public void init(FilterConfig filterConfig) throws ServletException
/*     */   {
/* 115 */     this.config = filterConfig;
/*     */   }
/*     */ }

/* Location:           E:\chenya\2017 4-21\com.chw\filter\
 * Qualified Name:     com.chw.filter.LoginAdminFilter
 * JD-Core Version:    0.6.0
 */